package com.itlong.cloud.operate.resource;

import com.itlong.cloud.POJO.DTO.operate.OperateDeviceAuthFileDTO;
import com.itlong.cloud.POJO.VO.operate.DeviceAuthFileVO;
import com.itlong.cloud.equip.operate.IOperateDeviceWhiteListAuthFileServiceClient;
import com.itlong.cloud.equip.operate.IOperateDeviceWhiteListServiceClient;
import com.itlong.cloud.operate.service.IOperateDeviceWhiteListAuthFileService;
import com.itlong.cloud.utils.data.handler.SqlUtil;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <desc>
 *      运营-设备白名单授权文件管理接口暴露实现类
 * </desc>
 *
 * @createDate2020/8/13
 **/
@RestController
public class OperateDeviceWhiteListAuthFileServiceResource implements IOperateDeviceWhiteListAuthFileServiceClient {

    @Autowired
    private IOperateDeviceWhiteListAuthFileService iOperateDeviceWhiteListAuthFileService;
    /**
     * <desc>
     *      分页获取授权文件列表
     * </desc>
     *
     * @param operateDeviceAuthFileDTO  授权文件参数DTO
     * @return 授权文件分页列表
     * @Author Zhu.yj
     * @createDate  2020/8/14
     */
    @PostMapping("/operate/whiteList/authFile/getPage")
    @Override
    public Page<DeviceAuthFileVO> getPage(@RequestBody OperateDeviceAuthFileDTO operateDeviceAuthFileDTO) throws Exception {
        return iOperateDeviceWhiteListAuthFileService.getPage(operateDeviceAuthFileDTO);
    }

    /**
     * <desc>
     *      保存授权文件信息
     * </desc>
     *
     * @param operateDeviceAuthFileDTO 授权文件参数DTO
     * @return 受影响行数
     * @Author Zhu.yj
     * @createDate  2020/8/14
     */
    @PostMapping("/operate/whiteList/authFile/save")
    @Override
    public Integer save(@RequestBody OperateDeviceAuthFileDTO operateDeviceAuthFileDTO) throws Exception {
        return iOperateDeviceWhiteListAuthFileService.save(operateDeviceAuthFileDTO);
    }

    /**
     * <desc>
     *      删除授权文件信息
     * </desc>
     *
     * @param operateDeviceAuthFileDTO 授权文件参数DTO
     * @return 受影响行数
     * @Author Zhu.yj
     * @createDate  2020/8/14
     */
    @Override
    public Integer delete(@RequestBody OperateDeviceAuthFileDTO operateDeviceAuthFileDTO) throws Exception {
        return iOperateDeviceWhiteListAuthFileService.delete(operateDeviceAuthFileDTO);
    }

    /**
     * <desc>
     * 获取授权文件信息
     * </desc>
     *
     * @param operateDeviceAuthFileDTO
     * @Author chengshican
     * @Date 2020-08-15 10:44
     * @Param arams 查询参数map
     * @Return 授权文件信息
     * @Exception
     */
    @RequestMapping(value = "/operate/whiteList/authFile/getEffectiveAuthFile",method = RequestMethod.POST)
    @Override
    public DeviceAuthFileVO getEffectiveAuthFile(@RequestBody OperateDeviceAuthFileDTO operateDeviceAuthFileDTO) throws Exception {

        return iOperateDeviceWhiteListAuthFileService.getEffectiveAuthFile(operateDeviceAuthFileDTO);
    }

    /**
     * <desc>
     * 根据授权文件id更新可用次数和已使用次数
     * </desc>
     *
     * @param operateDeviceAuthFileDTO
     * @Author chengshican
     * @Date 2020-08-16 9:20
     * @Param operateDeviceAuthFileDTO 授权文件参数DTO
     * @Return
     * @Exception
     */
    @RequestMapping(value = "/operate/whiteList/authFile/updateAuthFileByAuthId",method = RequestMethod.POST)
    @Override
    public int updateAuthFileByAuthId(@RequestBody OperateDeviceAuthFileDTO operateDeviceAuthFileDTO) throws Exception {
        return iOperateDeviceWhiteListAuthFileService.updateAuthFileByAuthId(operateDeviceAuthFileDTO);
    }

    /**
     * <desc>
     *      获取次数凭证地址
     * </desc>
     *
     * @param authId 授权文件id
     * @return 包含key为 fileName, fileUrl的map的集合
     * @Author Zhu.yj
     * @createDate  2020/8/16
     */
    @PostMapping("/operate/whiteList/authFile/getTimesEvidence")
    @Override
    public List<Map<String, Object>> getTimesEvidence(@RequestParam("authId") String authId) throws Exception {
        return iOperateDeviceWhiteListAuthFileService.getTimesEvidence(authId);
    }

    /**
     * <desc>
     *      根据文件名称获取文件数量
     * </desc>
     *
     * @param fileName 文件名称
     * @return 文件名为fileName的数量
     * @Author Zhu.yj
     * @createDate  2020/8/17
     */
    @PostMapping("/operate/whiteList/authFile/getCountByFileName")
    @Override
    public Integer getCountByFileName(@RequestParam("fileName") String fileName) throws Exception {
        return iOperateDeviceWhiteListAuthFileService.getCountByFileName(fileName);
    }
}
